package org.mog.music.controller;

import context.UserContext;
import dto.MusicLikeDTO;
import dto.MusicSearchDTO;
import entity.resullt.PageResult;
import entity.resullt.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.mog.music.service.IMusicService;
import org.springframework.web.bind.annotation.*;
import vo.MusicPageVO;

import javax.servlet.http.HttpServletRequest;

@RestController
@Api(tags = "在线音乐相关接口")
@RequestMapping("/user/online/music")
@RequiredArgsConstructor
@Slf4j
public class OnlineMusicController {
    private final IMusicService musicService;

    /**
     * 搜索音乐
     *
     * @param musicSearchDTO
     * @return
     */
    @GetMapping("/search")
    @ApiOperation("搜索音乐")
    public Result<PageResult<MusicPageVO>> searchMusic(MusicSearchDTO musicSearchDTO) {
        log.info("搜索音乐：{}", musicSearchDTO);
        PageResult<MusicPageVO> musicPageVoPageResult = musicService.searchMusic(musicSearchDTO);
        log.info("搜索成功：{}", musicPageVoPageResult);
        return Result.success(musicPageVoPageResult);
    }

    /**
     * 播放或下载音乐
     *
     * @param page
     * @param pageSize
     * @param n
     * @return
     */
    @GetMapping("/playOrDownload")
    @ApiOperation("播放或下载音乐")
    public Result<String> playOrDownloadMusic(Integer page,
                                              Integer pageSize,
                                              Integer n,
                                              String keyword,
                                              HttpServletRequest request) throws Exception {
        log.info("播放或下载音乐：page={}, pageSize={}, n={}", page, pageSize, n);
        String url = musicService.playOrDownloadMusic(page, pageSize, keyword, n, request);
        log.info("响应数据成功：{}", url);
        return Result.success(url);
    }
}
